import Vue from 'vue';
import Vuex from 'vuex';

import getters from'./getters'
import state from'./state'
import actions from'./actions'
import mutations from'./mutations'

Vue.use(Vuex);

const syncStorage = (store) => {
    var localstorageTimes = wx.getStorageSync("searchtimes");
	if (localstorageTimes) {
	    store.dispatch('LogSetSearchtimes', localstorageTimes)
	}
	
	var localstorageTimes2 = wx.getStorageSync("searchtimes2");
	if (localstorageTimes2) {
	    store.dispatch('LogSetSearchtimes2', localstorageTimes2)
	}
	
	var LogSetPhone = wx.getStorageSync("zguserphone");
	if (LogSetPhone) {
	    store.dispatch('LogSetPhone', LogSetPhone)
	}
	var LogSetOpenid = wx.getStorageSync("useropenid");
	if (LogSetOpenid) {
	    store.dispatch('LogSetOpenid', LogSetOpenid)
	}
	
	var LogSetPage = wx.getStorageSync("bxloginpage");
	if (LogSetPage) {
	    store.dispatch('LogSetPage', LogSetPage)
	}
	
	var LogSetFavzw = wx.getStorageSync("favzw");
	if (LogSetFavzw) {
	    store.dispatch('LogSetFavzw', LogSetFavzw)
	}
	
}

export default new Vuex.Store({
    getters,
    state,
    actions,
    mutations,
    plugins: [syncStorage]
})
